import { Global } from './../../common/global';
import { NativeProvider } from './../../providers/native/native';
import { BusiProvider } from './../../providers/busi/busi';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
/**
 * Generated class for the LoginPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
})
export class LoginPage {
  username: string = '张三';
  passowrd: string ='888888';
  xueyuanL = [];
  xueyuan:any ='信息学院';
  xuehao:any = '123456';
  constructor(public navCtrl: NavController, public navParams: NavParams, private busi: BusiProvider, private native: NativeProvider, public alertCtrl: AlertController) {
    this.username = localStorage.getItem(Global.username);
    this.getXyList();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad LoginPage');
  }

  login() {
    this.native.timer = 0;
    if (this.username == null || this.username == "") {
      this.native.alert("请输入姓名！");
      return;
    }

    if (this.passowrd == null || this.passowrd == "") {
      this.native.alert("请输入密码！");
      return;
    }
    let data = {
      name: this.username,
      password: this.passowrd,
      xuehao:this.xuehao,
      xueyuan:this.xueyuan
    }
    this.busi.login(data).subscribe(
      data => {
        localStorage.setItem(Global.username,this.username)
        localStorage.setItem(Global.token, data);
        this.navCtrl.setRoot("TabsPage");
      },
      error => {

      });
  }
  gotosetting(){
    this.navCtrl.push("SettingPage");
  }


  getXyList(){
    this.busi.getXueyuanList().subscribe(
      data=>{
        this.xueyuanL = data.dics;
      },
      error=>{
        console.log(error);
      }
    );
  }

}
